*===============================================================================
* Do-file creates "Table A6: : Administrative Dataset: Violence and M-Paisa Use, Adding District-level Controls"
*===============================================================================
clear 
set more off

cd "~/Dropbox/VFD/REStat_Native_Files/Stata_Files"
local output "~/Dropbox/VFD/REStat_Native_Files/Stata_Files/Output"



use "monthpanel_analysis_ANQAR.dta", clear
keep if salary==1
gen trimmedobs=0
sum balance, d
replace trimmedobs =1 if (balance <=r(p99) & balance>=r(p1))
replace trimmedobs =. if balance ==.
bys identityid: egen trimmed_extusers = min(trimmedobs)
keep if trimmed_extusers==1

xtset identityid ym
global controls age rural female educ_primary educ_secondary income_farming electricity_community pashtun

* Obtaining estimation sample
qui:reghdfe `y' d_violence_10km $controls, absorb(ym identityid c.ym#district) cluster(district)
gen sample=(e(sample))

*========================================================================
* TABLE A6: Panel A
*========================================================================
	foreach y in balance numtxns numwithdrawal numdeposit numtransferdebit { 
		reghdfe `y' d_violence_10km if sample, absorb(ym identityid c.ym#district) cluster(district)
		est store `y'
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary Users"
		estadd local monthFE "YES"
		estadd local distFE "YES"
		estadd local individFE "YES"
	}
	estout balance numtxns numwithdrawal numdeposit numtransferdebit ///
	using "`output'/table_a6a.tex", cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) ///
	starlevels(* .1 ** .05 *** .01) style(tex) keep(d_violence_10km) mlabels(, dep) collabels(,none) ///
	stats(samplestr in_sample_mean nID N_clust N r2 monthFE individFE distFE, fmt(0 3 0 0 0 3 0 0 0) ///
	label("Sample" "Mean Dep Var" "\# Individuals" "\# Clusters" "\# Observations" "R-Squared" "Month-Year FE" "Individual FE" "District Trends")) ///
	label title("Administrative Dataset: Violence and M-Paisa Use") replace


*========================================================================
* TABLE A6: Panel B
*========================================================================
	foreach y in balance numtxns numwithdrawal numdeposit numtransferdebit { 
		reghdfe `y' d_df_10km d_idf_10km d_ied_10km if sample, absorb(ym identityid c.ym#district) cluster(district)
		est store `y'
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary Users"
		estadd local monthFE "YES"
		estadd local distFE "YES"
		estadd local individFE "YES"
	}
	estout balance numtxns numwithdrawal numdeposit numtransferdebit ///
	using "`output'/table_a6b.tex", cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) ///
	starlevels(* .1 ** .05 *** .01) style(tex) keep(d_df_10km d_ied_10km d_idf_10km) mlabels(, dep) collabels(,none) ///
	stats(samplestr in_sample_mean nID N_clust N r2 monthFE individFE distFE, fmt(0 3 0 0 0 3 0 0 0) ///
	label("Sample" "Mean Dep Var" "\# Individuals" "\# Clusters" "\# Observations" "R-Squared" "Month-Year FE" "Individual FE" "District Trends")) ///
	label title("Administrative Dataset: Violence and M-Paisa Use") replace

	
*========================================================================
* TABLE A6: Panel C
*========================================================================
	foreach y in balance numtxns numwithdrawal numdeposit numtransferdebit { 
		reghdfe `y' d_violence_10km $controls, absorb(ym identityid c.ym#district) cluster(district)
		est store `y'
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary Users"
		estadd local monthFE "YES"
		estadd local distFE "YES"
		estadd local individFE "YES"
	}
	estout balance numtxns numwithdrawal numdeposit numtransferdebit ///
	using "`output'/table_a6c.tex", cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) ///
	starlevels(* .1 ** .05 *** .01) style(tex) keep(d_violence_10km) mlabels(, dep) collabels(,none) ///
	stats(samplestr in_sample_mean nID N_clust N r2 monthFE individFE distFE, fmt(0 3 0 0 0 3 0 0 0) ///
	label("Sample" "Mean Dep Var" "\# Individuals" "\# Clusters" "\# Observations" "R-Squared" "Month-Year FE" "Individual FE" "District Trends")) ///
	label title("Administrative Dataset: Violence and M-Paisa Use") replace


*========================================================================
* TABLE A6: Panel D
*========================================================================
	foreach y in balance numtxns numwithdrawal numdeposit numtransferdebit { 
		reghdfe `y' d_df_10km d_idf_10km d_ied_10km $controls, absorb(ym identityid c.ym#district) cluster(district)
		est store `y'
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary Users"
		estadd local monthFE "YES"
		estadd local distFE "YES"
		estadd local individFE "YES"
	}
	estout balance numtxns numwithdrawal numdeposit numtransferdebit ///
	using "`output'/table_a6d.tex", cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) ///
	starlevels(* .1 ** .05 *** .01) style(tex) keep(d_df_10km d_ied_10km d_idf_10km) mlabels(, dep) collabels(,none) ///
	stats(samplestr in_sample_mean nID N_clust N r2 monthFE individFE distFE, fmt(0 3 0 0 0 3 0 0 0) ///
	label("Sample" "Mean Dep Var" "\# Individuals" "\# Clusters" "\# Observations" "R-Squared" "Month-Year FE" "Individual FE" "District Trends")) ///
	label title("Administrative Dataset: Violence and M-Paisa Use") replace



	
